package array;

import java.util.HashMap;

public class leetCode1_twoSum {
    public int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        if(nums == null || nums.length == 0) return null;
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(hashMap.containsKey(target - nums[i])){
                res[0] = i;
                res[1] = hashMap.get(target - nums[i]);
            }else{
                hashMap.put(nums[i],i);
            }
        }
        return res;
    }
}
